<template>
    <el-button @click="addSubtitleClick" type="primary">
        {{ "添加字幕" }}
    </el-button>
</template>
<script>
// import { mapState } from "vuex";
import { addSubTitle, getFirstFrame } from "@/module/useFfmpeg";
export default {
    props:['obj'],
    // computed: {
    //     ...mapState({
    //         videoList: (state) => state.app.videoList,
    //         videoSelected: (state) => state.app.videoSelected,
    //         subtitleList: (state) => state.app.subtitleList,
    //         store: (state) => state.app.store,
    //     }),
    // },
    methods: {
        async addSubtitleClick() {
            if (this.obj.subtitleList.length == 0)
                return alert("请先上传字幕文件");
            const fileName = `video${this.obj.videoId++}`;
            const selectItem = this.obj.videoList[this.obj.videoSelected];
            const videoUrl = await addSubTitle(
                selectItem.videoUrl,
                selectItem.fileName
            );
            const { url: coverUrl, videoInfo } = await getFirstFrame(
                videoUrl,
                fileName
            );
            this.obj.videoList.push({
                videoUrl,
                coverUrl,
                fileName,
                videoInfo,
            });
        },
    },
};
</script>

